package com.xgpro.pc.rolemanage.controller;

import com.xgpro.common.results.ResponseResult;
import com.xgpro.domain.rolemanage.entity.Permissions;
import com.xgpro.pc.rolemanage.service.PermissionsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: xgpro__dev
 * @Description: 权限
 * @Author: wangyang
 * @Date: 2019-09-15 09:59
 **/

@RestController
@RequestMapping("/permissions")
public class PermissionsController {

    @Autowired
    private PermissionsService permissionsService;

    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/addRole",method = RequestMethod.POST)
    public ResponseResult addpermissions(@RequestBody Permissions permissions) {
        return permissionsService.addPermissions(permissions);
    }

    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/deletePermissions",method = RequestMethod.DELETE)
    public ResponseResult deletePermissions(@RequestParam("ids") List<Integer> ids) {
        return permissionsService.deletePermissions(ids);
    }

    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/updatePermissions",method = RequestMethod.PUT)
    public ResponseResult updatePermissions(@RequestBody Permissions permissions) {
        return permissionsService.updatePermissions(permissions);
    }

    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/getPermissions",method = RequestMethod.GET)
    public ResponseResult getPermissions(Integer id, Integer pageNum, Integer pageSize,Integer type,String name,Integer pid) {
        return permissionsService.getPermissions(id,pageNum,pageSize,type,name,pid);
    }
    @CrossOrigin(allowCredentials="true")
    @RequestMapping(value = "/findPerIdList")
    public ResponseResult findPerIdByRoleId(@RequestParam Integer roleId,@RequestParam Integer pid){

        return ResponseResult.ok(permissionsService.findPerIdByRoleId(roleId,pid));

    }
}